<template>
  <div id="permission">
    <el-form ref="tableData" :model="tableData" label-width="80px">
      <el-form-item label="角色名称">
        <el-input v-model="tableData.name" placeholder="角色名称查询"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-plus" @click="dialogFormVisible = true">添加权限</el-button>

        <el-dialog title="添加  权限" :visible.sync="dialogFormVisible">
          <el-form :model="tableData">
            <el-form-item label="权限名称" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="tableData.name" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="权限标识" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="tableData.sign" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="权限URL" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="tableData.address" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="权限备注" :label-width="formLabelWidth" style="margin-bottom:20px;">
              <el-input v-model="tableData.des" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
          </div>
        </el-dialog>

        <span style="margin-left:800px;">
          <el-button type="primary" icon="el-icon-search">查询</el-button>
          <el-button type="primary" icon="icon-zhongzhi">重置</el-button>
        </span>
      </el-form-item>
    </el-form>
    <el-table :data="tableData.slice((currentPage-1)*pagesize,currentPage*pagesize)" border style="width: 100%">
      <el-table-column prop="id" label="id" width="180">
      </el-table-column>
      <el-table-column prop="name" label="权限名称" width="180">
      </el-table-column>
      <el-table-column prop="sign" label="权限">
      </el-table-column>
      <el-table-column prop="address" label="接口URL">
      </el-table-column>
      <el-table-column prop="des" label="说明">
      </el-table-column>
      <el-table-column label="Action">

        <template slot-scope="scope">
          <el-button type='primary' plain @click="setInfo(scope.row)">编辑</el-button>
         
          <el-button type="danger" plain @click="dec">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
     <el-dialog title="编辑  权限" :visible.sync="dialogFormVisible">
            <el-form :model="form" ref="form">
              <el-form-item label="权限名称" :label-width="formLabelWidth" style="margin-bottom:20px;">
                <el-input v-model="form.name" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="权限标识" :label-width="formLabelWidth" style="margin-bottom:20px;">
                <el-input v-model="form.sign" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="权限URL" :label-width="formLabelWidth" style="margin-bottom:20px;">
                <el-input v-model="form.address" autocomplete="off"></el-input>
              </el-form-item>
              <el-form-item label="权限备注" :label-width="formLabelWidth" style="margin-bottom:20px;">
                <el-input v-model="form.des" autocomplete="off"></el-input>
              </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
              <el-button @click="dialogFormVisible = false">取 消</el-button>
              <el-button type="primary" @click="dialogFormVisible = false">确 定</el-button>
            </div>
          </el-dialog>
    <el-pagination style="margin-left:820px;margin-top:20px;" @size-change="handleSizeChange"
      @current-change="handleCurrentChange" :page-sizes="[4,8]" :page-size="100"
      layout="total, sizes, prev, pager, next, jumper" :total="tableData.length">
    </el-pagination>
  </div>
</template>
<script>
  // import axios from 'axios'
  export default {
    name: 'permission',
    data() {
      return {
        form: {
          name: '',
          sign: '',
          address: '',
          des: ''
        },
        formLabelWidth: '120px',
        dialogFormVisible: false,
        currentPage: 1, // 默认开始页面
        pagesize: 4,
        total: 0,
        tableData: [{
          id: '2016-05-02',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1518 弄',
          address: '上海市普陀区金沙江路 1518 弄',
          des: '上海市普陀区金沙江路 1518 弄'
        }, {
          id: '2016-05-04',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1517 弄',
          address: '上海市普陀区金沙江路 1517 弄',
          des: '上海市普陀区金沙江路 1517 弄'
        }, {
          id: '2016-05-01',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1519 弄',
          address: '上海市普陀区金沙江路 1519 弄',
          des: '上海市普陀区金沙江路 1519 弄'
        }, {
          id: '2016-05-03',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1516 弄',
          address: '上海市普陀区金沙江路 1516 弄',
          des: '上海市普陀区金沙江路 1516 弄'
        }, {
          id: '2016-05-03',
          name: '王小虎',
          sign: '上海市普陀区金沙江路 1516 弄',
          address: '上海市普陀区金沙江路 1516 弄',
          des: '上海市普陀区金沙江路 1516 弄'
        }]
      }
    },
    // created () {
    //   this.getinfo()
    // },
    methods: {
      handleSizeChange(size) {
        console.log(`每页 ${size} 条`)
        this.pagesize = size
      },
      handleCurrentChange(currentPage) {
        this.currentPage = currentPage
        console.log(`当前页: ${currentPage}`)
      },
      dec() {
        this.$message('孩子，不要删除啦！！！')
      },
      setInfo(info) {
        this.form = info;
        this.dialogFormVisible = true;
      },
      // getinfo () {
      //   // var that = this
      //   axios
      //     .get('http://47.108.201.43:3000/api/getGroupRoutes', {
      //       // params: { pageNum: 1, pageSize: 40 }
      //     })
      //     .then(function (res) {
      //       console.log(res)
      //       // that.tableData = res.data.data
      //     })
      // }
    }
  }
</script>
<style scoped>
  .el-input {
    width: 200px;
  }
</style>